#include <xc.h>
#include <timer.h>
#include "ChargeControl.h"
#include "TemperatureStuff.h"
#include "Config.h"

#ifdef USE_CRYSTAL
const int OverflowCount = 15625;
#else
const int OverflowCount = 31250;
#endif

void InitializeTimer()
{
    ConfigIntTimer1(T1_INT_PRIOR_3 & T1_INT_ON);
    OpenTimer1(T1_ON & T1_IDLE_CON & T1_GATE_OFF &
               T1_PS_1_64 & T1_SYNC_EXT_OFF & T1_SOURCE_INT, OverflowCount);
}

void __attribute__((__interrupt__, __auto_psv__)) _T1Interrupt(void)
{
    CC_HandleTimerExpiration();
    TS_HandleTimerTick();
    IFS0bits.T1IF = 0;
}

